<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">产品信息</ui:define>
    <ui:define name="content">
        <h:form id="incomeForm">
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="right">
                        <p:commandButton value="编辑" icon="fa fa-edit"
                                         actionListener="#{settlementProductInfoBean.changeStatusToEdit}"
                                         process="@this"
                                         update="@form" rendered="#{settlementProductInfoBean.isView()}"/>
                        <p:commandButton value="保存" icon="fa fa-save"
                                         action="#{settlementProductInfoBean.onSave()}"
                                         update="@form"
                                         rendered="#{settlementProductInfoBean.isAdd() || settlementProductInfoBean.isEdit()}"/>
                        <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-g ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12 ">
                    <div class="ui-g-12 card">
                        <h1>基础信息</h1>
                        <div class="ui-g-2">
                            <p:outputLabel value="产品名称"/>
                        </div>
                        <div class="ui-g-4">
                            <p:inputText id="productName" value="#{settlementProductInfoBean.$.productName}"
                                         disabled="#{settlementProductInfoBean.isView()}"/>
                        </div>

                        <div class="ui-g-2">
                            <p:outputLabel value="合作模式"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu id="copMode" value="#{settlementProductInfoBean.$.copMode}"
                                             disabled="#{settlementProductInfoBean.isView()}">
                                <p:ajax event="change" listener="#{settlementProductInfoBean.onChangeCopMode()}" process="@this"
                                        update="pricePanel"/>
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementProductInfoBean.dictionaries[DictionaryCode.COOPERATION_MODE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-2">
                            <p:outputLabel value="结算方式"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu id="settlementMode" value="#{settlementProductInfoBean.$.settlementMode}"
                                             disabled="#{settlementProductInfoBean.isView()}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementProductInfoBean.dictionaries[DictionaryCode.SETTLEMENT_CYCLE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>


                        <div class="ui-g-2">
                            <p:outputLabel value="收入类型"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu id="incomeType" value="#{settlementProductInfoBean.$.incomeType}"
                                             disabled="#{settlementProductInfoBean.isView()}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementProductInfoBean.dictionaries[DictionaryCode.SETTLEMENT_INCOME_TYPE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>
                        <p:outputPanel id="pricePanel">
                            <p:outputPanel rendered="#{settlementProductInfoBean.$.copMode==0
                                    || settlementProductInfoBean.$.copMode==2
                                    || settlementProductInfoBean.$.copMode==3}">
                                <div class="ui-g-2">
                                    <p:outputLabel value="结算价格（元）"/>
                                </div>
                                <div class="ui-g-4">
                                    <p:inputNumber id="priceCpa" value="#{settlementProductInfoBean.$.priceCpa}"
                                                 disabled="#{settlementProductInfoBean.isView()}">
                                    </p:inputNumber>
                                </div>
                            </p:outputPanel>

                            <p:outputPanel rendered="#{settlementProductInfoBean.$.copMode==1
                                          || settlementProductInfoBean.$.copMode==3}">
                                <div class="ui-g-2">
                                    <p:outputLabel value="结算价格（%）"/>
                                </div>
                                <div class="ui-g-4">
                                    <p:inputText id="priceCps" value="#{settlementProductInfoBean.$.priceCps}"
                                                 disabled="#{settlementProductInfoBean.isView()}">
                                        <f:convertNumber pattern="#0.00"/>
                                    </p:inputText>
                                </div>
                            </p:outputPanel>
                        </p:outputPanel>
                        <div class="ui-g-12 padding0">
                            <div class="ui-g-2">
                                <p:outputLabel value="关联活动"/>
                            </div>
                            <div class="ui-g-10">
                                <p:selectCheckboxMenu
                                                      value="#{settlementProductInfoBean.activityIdList}"
                                                      updateLabel="true" multiple="true" filter="true"
                                                      filterMatchMode="contains"
                                                      disabled="#{settlementProductInfoBean.isView()}">
                                    <f:selectItems value="#{settlementProductInfoBean.activityList}" var="activity"
                                                   itemValue="#{activity.id}"
                                                   itemLabel="#{activity.name}(#{activity.id})"/>
                                </p:selectCheckboxMenu>
                            </div>
                        </div>
                        <div class="ui-g-12 padding0">
                            <div class="ui-g-2">
                                <p:outputLabel  value="备注"/>
                            </div>
                            <div class="ui-g-10">
                                <p:inputText id="remark" value="#{settlementProductInfoBean.$.remark}"
                                             disabled="#{settlementProductInfoBean.isView()}"/>
                            </div>
                        </div>

                    </div>

                    <p:outputPanel styleClass="ui-g-12 padding0" rendered="#{settlementProductInfoBean.incomeRequest.productId != null}">

                        <div class="ui-g-12 card">
                            <div class="" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);margin-bottom: 10px">
                                <p:toolbar>
                                    <f:facet name="left">
                                        <p:commandButton id="toggler" type="button" value="展示选择"
                                                         style="width: auto;"
                                                         icon="ui-icon-calculator"/>
                                        <p:columnToggler datasource="statisticRecordDataTable" trigger="toggler"/>
                                    </f:facet>
                                    <f:facet name="right">
                                        <p:commandButton value="新增" actionListener="#{settlementIncomeListBean.onAdd(settlementProductInfoBean.$.id)}"
                                                         oncomplete="PF('adding').show();" process="@this" update="@form"
                                                         icon="fa fa-plus">
                                        </p:commandButton>
                                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                                         update="statisticRecordDataTable" ajax="true"/>
                                        <p:commandButton value="重置" actionListener="#{settlementProductInfoBean.onReset()}"
                                                         icon="fa fa-refresh"
                                                         process="@this" update="@form"/>
                                        <p:commandButton value="导出" icon="fa fa-download"
                                                         ajax="false">
                                            <p:dataExporter type="xls" target="statisticRecordDataTable" fileName="#{settlementProductInfoBean.$.productName}-消耗记录"/>
                                        </p:commandButton>
                                    </f:facet>
                                </p:toolbar>
                            </div>
                            <h1>查询条件</h1>
                            <div class="ui-g-1">
                                <p:outputLabel value="结算时间"/>
                            </div>
                            <div class="ui-g-3">
                                <p:calendar
                                        id="startTime" styleClass="autoWidthCalendar"
                                        value="#{settlementProductInfoBean.incomeRequest.startTime}"
                                        locale="#{constants:get('LOCALE')}"
                                        timeZone="#{constants:get('TIME_ZONE')}"
                                        pattern="#{constants:get('DATE_FORMAT')}"/>
                                <span>—</span>
                                <p:calendar
                                        id="endTime" styleClass="autoWidthCalendar"
                                        value="#{settlementProductInfoBean.incomeRequest.endTime}"
                                        locale="#{constants:get('LOCALE')}"
                                        timeZone="#{constants:get('TIME_ZONE')}"
                                        pattern="#{constants:get('DATE_FORMAT')}"/>
                            </div>
                            <p:dataTable id="statisticRecordDataTable"
                                         style="width: 100%;text-align:center"
                                         var="record"
                                         value="#{settlementProductInfoBean.incomeResponseLazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="98%"
                                         reflow="true"
                                         selection=""
                                         resizableColumns="true">
                                <p:column headerText="操作" exportable="false">
                                    <p:splitButton icon="fa fa-eye"
                                                   process="@this"
                                                   actionListener="#{settlementIncomeListBean.onSee(record.id)}"
                                                   oncomplete="PF('adding').show();" update="@form">
                                    </p:splitButton>
                                </p:column>
                                <p:column headerText="开始时间" style="text-align:center;width: 70px">
                                    <h:outputText value="#{record.startTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="结束时间" style="text-align:center;width: 70px">
                                    <h:outputText value="#{record.endTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="产品名称">
                                    <h:outputText value="#{record.productName}"/>
                                </p:column>
                                <p:column headerText="所属主体">
                                    <h:outputText value="#{record.companyName}"/>
                                </p:column>
                                <p:column headerText="收入类型" style="text-align:center;">
                                    <h:outputText
                                            value="#{settlementProductInfoBean.translate(DictionaryCode.SETTLEMENT_INCOME_TYPE,record.incomeType)}"/>
                                </p:column>
                                <p:column headerText="推广方式" style="text-align:center;">
                                    <h:outputText
                                            value="#{settlementProductInfoBean.translate(DictionaryCode.SETTLEMENT_SPREAD_MODE,record.spreadMode)}"/>
                                </p:column>
                                <p:column headerText="推广渠道" style="text-align:center;">
                                    <h:outputText
                                            value="#{settlementProductInfoBean.translate(DictionaryCode.SETTLEMENT_SPREAD_CHANNEL,record.spreadChannel)}"/>
                                </p:column>
                                <p:column headerText="合作模式" style="text-align:center;">
                                    <h:outputText
                                            value="#{settlementProductInfoBean.translate(DictionaryCode.COOPERATION_MODE,record.copMode)}"/>
                                </p:column>
                                <p:column headerText="结算方式" style="text-align:center;">
                                    <h:outputText
                                            value="#{settlementProductInfoBean.translate(DictionaryCode.SETTLEMENT_CYCLE,record.settlementMode)}"/>
                                </p:column>

                                <p:column headerText="结算单价(元)" style="text-align:center;">
                                    <h:outputText value="#{record.priceCpa == null ?'-':record.priceCpa}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="结算单价(%)" style="text-align:center;">
                                    <h:outputText value="#{record.priceCps == null?'-':record.priceCps}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="注册数" style="text-align:center;">
                                    <h:outputText value="#{record.registerCount == null ?'-': record.registerCount}"/>
                                </p:column>
                                <p:column headerText="放款金额" style="text-align:center;">
                                    <h:outputText value="#{record.lendAmount == null ?'-': record.lendAmount}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="点击数" style="text-align:center;">
                                    <h:outputText value="#{record.clickCount == null ?'-': record.clickCount}"/>
                                </p:column>
                                <p:column headerText="结算金额" style="text-align:center;">
                                    <h:outputText value="#{record.incomeAmount}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="参与UV" style="text-align:center;">
                                    <h:outputText value="#{record.participateUv}"/>
                                </p:column>
                                <p:column headerText="UV价值" style="text-align:center;">
                                    <h:outputText value="#{record.uvValue}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="开票状态" style="text-align:center;">
                                    <h:outputText value="未开票" rendered="#{record.billStatus==0}" style="color: red"/>
                                    <h:outputText value="财务专员审核中" rendered="#{record.billStatus==1}" style="color: olivedrab"/>
                                    <h:outputText value="财务经理审核中" rendered="#{record.billStatus==2}" style="color: olivedrab"/>
                                    <h:outputText value="已开票" rendered="#{record.billStatus==3}" style="color: blue"/>
                                </p:column>
                                <p:column headerText="创建人" style="text-align:center;">
                                    <h:outputText value="#{record.creator}"/>
                                </p:column>
                                <p:column headerText="创建时间" style="text-align:center;width: 100px">
                                    <h:outputText value="#{record.createTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                            </p:dataTable>
                        </div>

                    </p:outputPanel>
                </div>
            </div>
            <ui:include src="income-info-dialog.xhtml"/>
        </h:form>
    </ui:define>
</ui:composition>